<?php
namespace app\common\controller\storage;

use think\Controller;

/**
 * 云存储
 */
class CloudStorage extends Upload
{
    /**
     * 初始化方法
     */
    protected function initialize()
    {
        parent::initialize();
        // 阿里云OSS
        $this->aliYunOss = new AliYunOss;
        // 七牛云Kodo
        $this->qiniuKodo = new QiniuKodo;
        // 本地存储
        $this->localStorage = new LocalStorage;
    }

    /**
     * 云存储统一文件上传入口
     * (new \app\common\controller\CloudStorage)->upload('img');
     */
    public function upload($name)
    {
        switch ($this->storageType) {
            case 1:
                // 七牛云 Kodo
                $obj = $this->qiniuKodo;
                break;
            case 2:
                // 阿里云 OSS
                $obj = $this->aliYunOss;
                break;
            default:
                $obj = $this->localStorage;
                break;
        }
        return $obj->upload($name);
    }
}